<?php

namespace app\index\controller;

use app\common\library\enum\OrderStatusEnum;

class Order extends Base
{
    /**
     * 商户交易订单
     *
     *     *
     * @return mixed
     */
    public function index()
    {

        $where = ['a.uid' => is_login()];

        //组合搜索
        !empty($this->request->get('trade_no')) && $where['a.trade_no|a.out_trade_no']
            = ['like', '%' . $this->request->param('trade_no') . '%'];

        !empty($this->request->get('channel')) && $where['a.channel']
            = ['eq', $this->request->param('channel')];

        //时间搜索  时间戳搜素
        //$where['a.create_time'] = $this->parseRequestDate();

        //状态
        is_numeric($this->request->param('status')) && $where['a.status']
            = ['eq', $this->request->param('status')];


        $dateRange = $this->request->param('range');
        if (empty($dateRange)) {
            $dateRange = date("Y-m-d 00:00:00 ~ Y-m-d 23:59:59");
        }


        $this->assign("dateRange", $dateRange);

        $dateStart = substr($dateRange, 0, 19);
        $dateEnd = substr($dateRange, -19);

        $where['a.create_time'] = ['between', [strtotime($dateStart), strtotime($dateEnd)]];

        $this->assign('code', $this->logicPay->getCodeList([]));
        $stat = $this->logicOrders->getOrderStatNew($where);
        $this->assign("stat", $stat[0]);

        $this->assign('list', $this->logicOrders->getOrderListNew($where, true, 'a.create_time desc', 10));

        return $this->fetch();
    }

    /**
     * 商户退款订单
     *
     *     *
     * @return mixed
     */
    public function refund()
    {

        $where = ['uid' => is_login()];

        //组合搜索
        !empty($this->request->get('trade_no')) && $where['trade_no']
            = ['like', '%' . $this->request->get('trade_no') . '%'];

        !empty($this->request->get('channel')) && $where['channel']
            = ['eq', $this->request->get('channel')];

        //时间搜索  时间戳搜素
        $where['create_time'] = $this->parseRequestDate();

        //状态
        $where['status'] = ['eq', $this->request->get('status', OrderStatusEnum::UNPAID)];
        //halt($this->logicOrders->getOrderList($where,true, 'create_time desc', 10));
        $this->assign('list', $this->logicOrders->getOrderList($where, true, 'create_time desc', 10));

        return $this->fetch();
    }

    /**
     *
     *     *
     * @return mixed
     */
    public function submit()
    {
        $where = ['uid' => is_login()];
        $this->assign('list', $this->logicOrders->getOrderList($where, true, 'create_time desc', 10));
        return $this->fetch();
    }
}
